import {mapGetters} from 'vuex'

export default {
  computed:{
    ...mapGetters('m_cart',['total'])
  },
  watch:{
    total:{
      handler(newVal){
        this.setBadge()
        this.removeBadge()
      }
    }
  },
  onShow(){
      this.setBadge()
      this.removeBadge()
  },
  methods:{
    setBadge(){
      uni.setTabBarBadge({
        index: 2,
        text: this.total+''
      })
    },
    removeBadge(){
      if(this.total===0){
        uni.removeTabBarBadge({
          index: 2,
        })
      }
    }
  }
}